//
//  TeaStuLessonInfoTableViewCell.m
//  LoveDraw
//
//  Created by 零零壹 on 2017/9/23.
//  Copyright © 2017年 梁晨. All rights reserved.
//

#import "TeaStuLessonInfoTableViewCell.h"
#import "TeaStuHeadTableViewCell.h"

@implementation TeaStuLessonInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumLineSpacing = 2;
        layout.minimumInteritemSpacing = 2;
        layout.sectionInset = UIEdgeInsetsMake(8, 20, 8, 20);
        layout.itemSize = CGSizeMake((KscreenW-40-20)/10, (KscreenW-40-20)/10);
        self.MineCollectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KscreenW, 0) collectionViewLayout:layout];
        [self.contentView addSubview:self.MineCollectionV];
        self.MineCollectionV.backgroundColor = [UIColor whiteColor];
        [self.MineCollectionV registerNib:[UINib nibWithNibName:@"TeaStuLessonInfoCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"TeaStuLessonInfoCollectionViewCell"];
        self.MineCollectionV.delegate = self;
        self.MineCollectionV.dataSource = self;
        [self.contentView addSubview:self.MineCollectionV];
    }
    return self;
}

-(void)setCollectVFrame
{
    NSLog(@"classhour_total=======%ld",[self.infoDic[@"classhour_total"] integerValue]);
    self.MineCollectionV.frame = CGRectMake(0, 0, KscreenW, [self.infoDic[@"classhour_total"] integerValue]/10.0*(KscreenW-60)/10+16+20);
}

//-(NSDictionary *)infoDic
//{
//    NSLog(@"classhour_total=======%ld",[self.infoDic[@"classhour_total"] integerValue]);
//    self.MineCollectionV.frame = CGRectMake(0, 0, KscreenW, [self.infoDic[@"classhour_total"] integerValue]/10.0*(KscreenW-60)/10+16);
//}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [self.infoDic[@"classhour_total"] integerValue];
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TeaStuLessonInfoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TeaStuLessonInfoCollectionViewCell" forIndexPath:indexPath];

     int useClass = [self.infoDic[@"classhour_total"] intValue]-[self.infoDic[@"classhour_last"] intValue]-[self.infoDic[@"classhour_give"] intValue];
    int payClass = [self.infoDic[@"payclasshour"] intValue];

    if (useClass>payClass)
    {
        if (indexPath.row<payClass) {
            [cell.MineImageV setImage:[UIImage imageNamed:@"buy_01"]];
        }else if (indexPath.row>=payClass && indexPath.row < useClass)
        {
            [cell.MineImageV setImage:[UIImage imageNamed:@"buy_04"]];
        }else if (indexPath.row>=useClass)
        {
            [cell.MineImageV setImage:[UIImage imageNamed:@"buy_03"]];
        }
    }else if (useClass < payClass) // 使用的课次数小于购买的课次数
    {
        if (indexPath.row<useClass) {
            [cell.MineImageV setImage:[UIImage imageNamed:@"buy_01"]];
        }else if (indexPath.row>=useClass && indexPath.row<payClass)
        {
            [cell.MineImageV setImage:[UIImage imageNamed:@"buy_02"]];
        }else
        {
            [cell.MineImageV setImage:[UIImage imageNamed:@"buy_03"]];
        }
    }
    return cell;
}

/*
 // 已经使用的课次数
 int useClass = [self.mode.classhour_total intValue]-[self.mode.classhour_last intValue]-[self.mode.classhour_give intValue];

 // 实际购买的课次数
 int payClass = [self.mode.payclasshour intValue];


 // 如果已经使用的课次数大于购买的 那么购买的全部使用了

 */
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)



@end
